package interview.huawei.training.p41;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextInt()) {
            // 砝码的种数
            int weightKinds = scanner.nextInt();
            // 每种砝码的重量
            int[] weights = new int[weightKinds];
            for(int i = 0; i < weightKinds; i++) {
                weights[i] = scanner.nextInt();
            }
            // 每种砝码的个数
            int[] weightCounts = new int[weightKinds];
            for(int i = 0; i < weightKinds; i++) {
                weightCounts[i] = scanner.nextInt();
            }

            // 存储所有称重的可能性
            HashSet<Integer> weightSet = new HashSet<>();
            // 第1种砝码可能的重量
            for (int i = 0; i <= weightCounts[0]; i++) {
                weightSet.add(weights[0] * i);
            }
            // 基于前几种砝码的重量往上加砝码
            for (int i = 1; i < weightKinds; i++) {
                List<Integer> list = new ArrayList<>(weightSet);
                for (int j = 0; j <= weightCounts[i]; j++) {
                    for (int k = 0; k < list.size(); k++) {
                        weightSet.add(list.get(k) + j * weights[i]);
                    }
                }
            }

            System.out.println(weightSet.size());
        }

        scanner.close();
    }
}